/**
 * Created by Administrator on 2017/10/12.
 */
require('../../../less/back/rent/rent_detail.less');
import $ from 'jQuery';
(function () {
    let $tree = null;
    let $vue = null;
    $vue = new Vue({
        el: '.create-alarm-main-hook',
        data: {
            paymentFlag:[{id: 0, name: '电容故障'}, {id: 1, name: '光源故障'}, {id: 2, name: '继电器故障'}, {id: 3, name: '保险丝故障'},
                {id: 4, name: '存储芯片故障'}, {id: 5, name: '时钟芯片故障'}, {id: 6, name: '读卡模块故障'}, {id: 7, name: '内部参数配置故障'},
                {id: 8, name: '漏电报警'}, {id: 9, name: '防盗报警'}, {id: 10, name: '水浸报警'}, {id: 11, name: '电流过大报警'},
                {id: 12, name: '功率过大报警'}, {id: 13, name: '功率过小报警'}, {id: 14, name: '其他'}],
            Number:[{id:1,name:'1'},{id:2,name:'2'},{id:3,name:'3'},{id:3,name:'3'}],
            account: {

            },
        },
        created: function () {
            IOT.getServerData(URI.ALARM.CREATE_ALARM.STORAGE_TREE, {}, (ret) => {
                if (ret.code === 200) {
                    let treeList = ret.data;
                    $tree = $.fn.zTree.init($('#alarm_tree'), setting, treeList);
                    $tree.expandAll(true);
                } else {
                    IOT.tips(ret.msg, 'error');
                }
            });
            var setting = {
                data: {
                    simpleData: {
                        enable: true,
                        idKey: 'id',
                        pIdKey: 'pid',
                        rootPId: 0
                    }
                },
                view:{
                    selectedMulti: false,//不允许同时选中多个节点
                    showIcon :false,
                    showLine:false,
                    /*addDiyDom: function addDiyDom(treeId, treeNode){
                        var sObj = $("#" + treeNode.tId + "_a");
                        var addStr = "<span class='pallent_span'>托盘数："+treeNode.palletCount+"</span>";
                        sObj.append(addStr);
                        //超过部分用“...”显示
                        var spaceWidth = 5;
                        var switchObj = $("#" + treeNode.tId + "_switch"),
                            icoObj = $("#" + treeNode.tId + "_ico");
                        switchObj.remove();
                        icoObj.parent().before(switchObj);
                        var spantxt = $("#" + treeNode.tId + "_span").html();
                        if (spantxt.length > 15) {
                            spantxt = spantxt.substring(0, 15) + "...";
                            $("#" + treeNode.tId + "_span").html(spantxt);
                        }
                    }*/
                },
                callback: {
                    onClick:function onCheckTreeNode(event, treeId, treeNode){
                        $('.address').val(treeNode.name);
                        $('.total-amount').val(treeNode.palletCount);
                        $('.company-name').val(treeNode.companyName);
                    }
                }
            };
        },
        computed: {

        },
        methods: {
            searchForm:function(){
                IOT.getServerData(URI.ALARM.CREATE_ALARM.SEARCHENTER, {}, (ret) => {
                    if (ret.code === 200) {

                    } else {
                        IOT.tips(ret.msg, 'error');
                    }
                });
            },
            cancleBack: function () {
                M.Page.emitPrePage();
                // M.Page.emitRefreshPage();
            },
            printOrder:function(){
                window.print();
            },
            saveEdit:function(){//确认按钮
                let params ={
                    orderNo:$vue.$data.account.orderNo,
                };
                IOT.showOverlay('保存中，请稍等...');
                IOT.getServerData(URI.ALARM.CREATE_ALARM.UPDATE, params, (ret) => {
                    IOT.tips(ret.msg || '操作失败，请重试！', 'error', 1000, null);
                    IOT.hideOverlay();
                    if (ret && ret.code === 200) {
                        IOT.tips('保存成功！', 'success');
                        layer.closeAll();
                        M.Page.emitPrePage();
                        M.Table.refresh.all();

                    } else {
                        IOT.tips(ret.message || '服务器请求失败，稍后再试！', 'error');
                    }
                });
            },
            noEdit:function(){//取消按钮
                M.Page.emitPrePage();
                M.Table.refresh.all();
            },
        },
        mounted: function () {

        }
    });
})();